class smx_cwebpdf {
  require smx_os

  Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

  exec { 'download-tomcat-package':
    command => "wget -O /usr/src/apache-tomcat-8.0.35.tar.gz https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.35/bin/apache-tomcat-8.0.35.tar.gz",
    path    => ['/usr/bin','/usr/sbin/','/bin','sbin'],
    creates => "/usr/src/apache-tomcat-8.0.35.tar.gz",
  }

  exec { 'untar apache-tomcat-8.0.35.tar.gz':
    command => "tar zxvf /usr/src/apache-tomcat-8.0.35.tar.gz -C /usr/local/",
    path    => ['/usr/bin','/usr/sbin','/bin','/sbin'],
    require => Exec['download-tomcat-package'],
  }

  exec { 'mv apache-tomcat-8.0.35 tomcat':
    cwd     => "/usr/local/",
    command => "mv apache-tomcat-8.0.35 tomcat",
    creates => "/usr/local/tomcat/bin/catalina.sh",
    require => Exec['untar apache-tomcat-8.0.35.tar.gz'],
  }

  file { '/vagrant/vagrant/download_cwebpdf.sh':
    ensure => present,
    mode   => '0755', owner => root, group => root,
    source =>  "puppet:///modules/smx_cwebpdf/download_cwebpdf.sh",
  }

  exec { 'download_cwebpdf':
    cwd       => '/vagrant/vagrant',
    command   => "/vagrant/vagrant/download_cwebpdf.sh",
    timeout   => '1800', # half an hour, at most
    logoutput => true,
    require   => File['/vagrant/vagrant/download_cwebpdf.sh'],
  }
  file { '/vagrant/vagrant/reader.xml':
    ensure => file,
    source => "puppet:///modules/smx_cwebpdf/reader.xml",
  }

  file { '/vagrant/vagrant/foxit-cwebpdf-filesystem.xml':
    ensure => file,
    source => "puppet:///modules/smx_cwebpdf/foxit-cwebpdf-filesystem.xml",
  }

  file { '/vagrant/vagrant/foxit-cwebpdf-collectiondata.xml':
    ensure => file,
    source => "puppet:///modules/smx_cwebpdf/foxit-cwebpdf-collectiondata.xml",
  }
  file { '/etc/init.d/fxtomcat':
    ensure => file,
    mode   => 0755,
    source => "puppet:///modules/smx_cwebpdf/fxtomcat",
  }
  service { 'fxtomcat':
    enable  => true,
    path    => "/etc/init.d",
    start   => "/etc/init.d/fxtomcat start",
    stop    => "/etc/init.d/fxtomcat stop",
    require => File['/etc/init.d/fxtomcat'],
  }

}  
